package com.dahua.messagesyncbj;

import com.dahua.messagesyncbj.runner.SyncScheduleRunner;
import com.dahua.messagesyncbj.service.EquipmentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

import static com.dahua.messagesyncbj.business.Constants.IS_INITIALIZE;

@Slf4j
@Component
public class InitializeRunner implements ApplicationRunner {
    @Resource
    private EquipmentService equipmentService;
    @Resource
    private SyncScheduleRunner syncScheduleRunner;

    @Override
    public void run(ApplicationArguments args) {
        this.cachePreheating();
        Thread thread = new Thread(syncScheduleRunner);
        thread.start();
    }

    public void cachePreheating() {
        //缓存预热
        equipmentService.resetEquipmentInfo();
        equipmentService.resetSensorInfoRemake();
        equipmentService.resetLatestStatus();
        equipmentService.checkInsertLatestStatus();
        IS_INITIALIZE = true;
        log.info("初始化完成");
    }
}
